
function validateUpdateHomeForm(formName)
{
    var currentField = document.forms[formName]["city"];
    
    // Check the city field
    if ( IsEmpty(currentField) )
    {
        alert("City must be specified.");
        GetAttention(currentField);       
        return false;
    }
    else LoseAttention(currentField);
    
    // Check the country field
    currentField = document.forms[formName]["country"];
    if ( IsEmpty(currentField) )
    {
        alert("Country must be specified.");
        GetAttention(currentField);       
        return false;
    }
    else LoseAttention(currentField);
    
    // Check the district field
    currentField = document.forms[formName]["district"];
    if ( IsEmpty(currentField) )
    {
        alert("District must be specified.");
        GetAttention(currentField);       
        return false;
    }
    else LoseAttention(currentField);

    // Check the zone field
    currentField = document.forms[formName]["zone"];
    if ( IsEmpty(currentField) )
    {
        alert("Zone must be specified.");
        GetAttention(currentField);       
        return false;
    }
    else LoseAttention(currentField);
    
    // Check the postal code field
    currentField = document.forms[formName]["postalcode"];
    if ( IsEmpty(currentField) )
    {
        alert("Postal code must be specified.");
        GetAttention(currentField);       
        return false;
    }
    else LoseAttention(currentField);

    // Check the lot size field
    currentField = document.forms[formName]["lotsize"];
    if ( !IsNumber(currentField.value) )
    {
        alert("Lot size must be a valid number.");
        GetAttention(currentField);       
        return false;
    }
    else LoseAttention(currentField);
    
    // Check the property type field
    currentField = document.forms[formName]["propertyType"];
    if ( IsEmpty(currentField) )
    {
        alert("A property type must be selected.");
        GetAttention(currentField);       
        return false;
    }
    else LoseAttention(currentField);    
    
    // Check the year built field
    currentField = document.forms[formName]["yearbuilt"];
    if ( !IsNumber(currentField.value) || currentField.value.length != 4 )
    {
        alert("Year built must be a valid number.");
        GetAttention(currentField);       
        return false;
    }
    else LoseAttention(currentField);
    
    // Check the heating field
    currentField = document.forms[formName]["heating"];
    if ( IsEmpty(currentField) )
    {
        alert("Heating must be selected.");
        GetAttention(currentField);       
        return false;
    }
    else LoseAttention(currentField);

    // Check the cooling field
    currentField = document.forms[formName]["cooling"];
    if ( IsEmpty(currentField) )
    {
        alert("Cooling must be selected.");
        GetAttention(currentField);       
        return false;
    }
    else LoseAttention(currentField);
    
    // Check the parking field
    currentField = document.forms[formName]["parking"];
    if ( IsEmpty(currentField) )
    {
        alert("Parking must be selected.");
        GetAttention(currentField);       
        return false;
    }
    else LoseAttention(currentField);

    // Check the garage field
    currentField = document.forms[formName]["garage"];
    if ( IsEmpty(currentField) )
    {
        alert("Garage must be selected.");
        GetAttention(currentField);       
        return false;
    }
    else LoseAttention(currentField);
    
    // Check the driveway field
    currentField = document.forms[formName]["driveway"];
    if ( IsEmpty(currentField) )
    {
        alert("Driveway must be selected.");
        GetAttention(currentField);       
        return false;
    }
    else LoseAttention(currentField);

    // Check the neighborhood field
    currentField = document.forms[formName]["neighborhood"];
    if ( IsEmpty(currentField) )
    {
        alert("A neighborhood must be specified.");
        GetAttention(currentField);       
        return false;
    }
    else LoseAttention(currentField);
    
    // Check the evaluated price field
    currentField = document.forms[formName]["evaluatedPrice"];
    if ( !IsNumber(currentField.value) )
    {
        alert("Evaluated price must be a valid number.");
        GetAttention(currentField);       
        return false;
    }
    else LoseAttention(currentField);    
    
    // Check the property taxes field
    currentField = document.forms[formName]["propertyTaxes"];
    if ( !IsNumber(currentField.value) )
    {
        alert("Property taxes must be a valid number.");
        GetAttention(currentField);       
        return false;
    }
    else LoseAttention(currentField);    
    
    // Check the utility cost field
    currentField = document.forms[formName]["utilityCost"];
    if ( !IsNumber(currentField.value) )
    {
        alert("Utility cost must be a valid number.");
        GetAttention(currentField);       
        return false;
    }
    else LoseAttention(currentField);
    
    // Check the price field
    currentField = document.forms[formName]["price"];
    if ( !IsNumber(currentField.value) )
    {
        alert("Price must be a valid number.");
        GetAttention(currentField);       
        return false;
    }
    else LoseAttention(currentField);    
    
    return true;        
}

function IsEmpty(field) {
   if( (field.value.length==0) || (field.value==null) ) 
   {
      return true;
   }
   else return false;
}

function IsNumber(n) {
  return !isNaN(parseFloat(n)) && isFinite(n);
}

function GetAttention(currentField) {
    currentField.focus();
    currentField.style.backgroundColor = "#FF6F6F";  
}

function LoseAttention(currentField) {
        currentField.style.backgroundColor = "#FFFFFF";      
}